public class SingleLinkedList {
    static class ListNode {
        public int val;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;

        }
        public ListNode(){

        };
    }

    public ListNode head;

    public void createList() {
        ListNode listNode1 = new ListNode(12);
        ListNode listNode2 = new ListNode(21);
        ListNode listNode3 = new ListNode(33);
        ListNode listNode4 = new ListNode(41);
        ListNode listNode5 = new ListNode(52);
        listNode1.next = listNode2;
        listNode2.next = listNode3;
        listNode3.next = listNode4;
        listNode4.next = listNode5;
        this.head = listNode1;
    }
    public ListNode mergeTwoList(ListNode headA,ListNode headB){
        if(headB==null||headA==null){
            return null;
        }
        ListNode newHead=new ListNode();
        ListNode tmpH=newHead;
        while (headA!=null&&headB!=null){
        if(headA.val<headB.val){
            tmpH.next=headA;
            tmpH=headA;//tmpH=tmpH.next
            headA=headA.next;
        }else {
            tmpH.next=headB;
            tmpH=headB;
            headB=headB.next;
        }
        }
        if(headA!=null){
            tmpH.next=headA;
        }
        if(headB!=null){
            tmpH.next=headB;
        }
        return newHead.next;



    }
}


